/*
 * @Author: hyman
 * @Date: 2022-02-10 10:38:51
 * @LastEditors: hyman
 * @LastEditTime: 2022-02-10 10:38:52
 * @Description: 请填写简介
 */
import React from 'react'
import {useNavigate} from 'react-router-dom'
import cookie from 'react-cookies'

class AuthRouter extends React.Component{
  constructor(props)
  {
    super(props)

    this.state = {}
  }

  render()
  {
    const AuthLogin = () =>
    {
      let navigate = useNavigate()
      React.useEffect(() => {
        var LoginUser = cookie.load('LoginUser') ? cookie.load('LoginUser') : {}
        if(JSON.stringify(LoginUser) === "{}")
        {
          navigate('/user/base/login')
        }
      })

      return false
    }

    return (
      <> 
        {
          this.props.auth && <AuthLogin />
        }
        {this.props.component}
      </>
    )
  }
}

export default AuthRouter